package com.yhn.init.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.menu.MenuAddRequest;
import com.yhn.init.model.dto.menu.MenuQueryRequest;
import com.yhn.init.model.dto.menu.MenuUpdateRequest;
import com.yhn.init.model.vo.MenuVO;
import com.yhn.init.service.MenuService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 菜单表
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private MenuService menuService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/menu/list")
    public BaseResponse<Page<MenuVO>> listByPage(@RequestBody MenuQueryRequest menuQueryRequest) {
        Page<MenuVO> page = menuService.queryPage(menuQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/menu/info")
    public BaseResponse<MenuVO> getInfoById(@PathVariable("id") Long id) {
        MenuVO menu = menuService.getInfoById(id);

        return ResultUtils.success(menu);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    // @SaCheckPermissions("furniture/menu/save")
    public BaseResponse<Long> save(@RequestBody MenuAddRequest menuAddRequest) {
        Long newId = menuService.saveMenu(menuAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/menu/update")
    public BaseResponse<Boolean> update(@RequestBody MenuUpdateRequest menuUpdateRequest) {
        boolean result = menuService.updateMenu(menuUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/menu/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = menuService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/menu/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = menuService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }
}
